/** 
 * File-Name:CommonAction.java
 *
 * Created on 2010-12-22 下午02:18:38
 * 
 * @author: Neo (neolimeng@gmail.com)
 * Software Engineering Institute, Peking University, China
 * 
 * Copyright (c) 2009, Peking University
 * 
 *
 */
package neoutil;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

/**
 * Description:Base Action class for the Tutorial package.
 * 
 * @author: Neo (neolimeng@gmail.com) Software Engineering Institute, Peking
 *          University, China
 * @version 1.0 2010-12-22 下午02:18:38
 */
public class CommonAction extends ActionSupport {
	public static final String RELOGIN = "relogin";
	public static final String EXCEPTION = "exception";

	protected String jsonResult;

	protected String errorMessage;

	protected String returnURL;

	protected Object getSessionObject(String key) {
		return ServletActionContext.getRequest().getSession().getAttribute(key);
	}

	protected void setSessionObject(String key, Object value) {
		ServletActionContext.getRequest().getSession().setAttribute(key, value);
	}

	protected String getRequestParameter(String key) {
		try {
			String rawParam = ServletActionContext.getRequest().getParameter(
					key);
			if (rawParam == null || "".equals(rawParam)) {
				return null;
			} else {
				return new String(rawParam.getBytes("iso-8859-1"), "UTF-8");
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public String getJsonResult() {
		return jsonResult;
	}

	public void setJsonResult(String jsonResult) {
		this.jsonResult = jsonResult;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	public String getReturnURL() {
		return returnURL;
	}

	public void setReturnURL(String returnURL) {
		this.returnURL = returnURL;
	}

}
